<?php
if(!defined('ADMIN')){
	exit('Access Denied');
}
$where=' status>-1';
$datelimit_start=empty($_POST['datelimit-start'])?mktime(0,0,0):strtotime($_POST['datelimit-start']);
$datelimit_end=empty($_POST['datelimit-end'])?mktime(0,0,0):strtotime($_POST['datelimit-end']);
if(empty($_POST)){
    $where.=" and giventime>=".($datelimit_start)." and giventime<=".($datelimit_end+86400-1)."";
}
$q=$_POST['q'];
$x=$_POST['x'];
if(!empty($q)&&$_POST['x']=='id'){
    $where.=" and id=".$q."";
}else if(!empty($q)&&$_POST['x']=='nickname'){
    $where.=" and nickname like '%".$q."%'  and giventime>=".($datelimit_start)." and giventime<=".($datelimit_end+86400-1)." ";
}else{
    $where.=" and giventime>=".($datelimit_start)." and giventime<=".($datelimit_end+86400-1)."";
}
$page = !($_POST['pageNum'])?'1':intval($_POST['pageNum']);
$pagesize= !($_POST['numPerPage'])?'20':intval($_POST['numPerPage']);

$item=array('starttime'=>$datelimit_start,'endtime'=>$datelimit_end);
if(empty($pagesize)){
    $pagesize=20;
}
$frmnum=($page-1)*$pagesize;
$orderField=trim($_POST["orderField"]);
$orderDirection=trim($_POST["orderDirection"]);
if(empty($orderField)){
    $orderField="id";
}
if(empty($orderDirection)){
    $orderDirection="desc";
}
if($orderField<>""){
    $order=" order by $orderField ".$orderDirection;
}else{
    $order=" order by id desc";
}






$total=$ezhand->count("coupon_given",$where);

$row=$ezhand->select_all("coupon_given",'*',''.$where.' '.$order.' limit '.$frmnum.','.$pagesize);
foreach($row as $key=>$val){
    $row[$key]['couponname']=$ezhand->get_namebycouponid("card_coupon","id={$val['coupon_id']}");
}
$ser=array('id'=>'id','nickname'=>'昵称');
?>
